<%-- 
    Document   : confirmEC
    Created on : Oct 21, 2013, 5:25:22 PM
    Author     : Thai Ha Cong
--%>

<%@page import="cart.ShoppingCartItem"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type='text/javaScript'>
            function checkedAll () {
            var inputs = document.getElementsByTagName('input');
            var checkboxes = [];
            var check = document.getElementById('mainCheckbox').checked
            for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'checkbox') {
            inputs[i].checked = check;
            }
            }
            }
        </script>
        <title>Paypal Express Checkout</title>
        <link href="<%= request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <div class="headerbg">
            <%@include file="include/iHeader.jsp" %>
        </div>
        <div class="contentbg">
            <div class="shoppingCart">
                <%
                    String emptyMessage;
                    if (scart == null) {
                        emptyMessage = "Empty Shopping Cart.";
                %>
                <div class="uniqueMessage">
                    <p><% out.print(emptyMessage);%></p>
                </div>
                <%
                } else if (scart.getTotalQuantity() == 0) {
                    emptyMessage = "Empty Shopping Cart.";
                %>
                <div class="uniqueMessage">
                    <p><% out.print(emptyMessage);%></p>
                </div>
                <%
                } else {
                %>
                <div class="itemsOnCart">
                    <table>
                        <s:form action="updateShoppingCart" method="POST">
                            <thead>
                                <tr>
                                    <th class="cQty">Quantity</th>
                                    <th class="cRem"><input type="checkbox" id="mainCheckbox" name="check/uncheck all" onclick='checkedAll();' readonly="true" disabled="true"/></th>
                                    <th class="cDes">Product Description</th>
                                    <th class="cPri">Price</th>
                                    <th class="cTot">Total Price</th>
                                </tr>
                            </thead>
                            <tbody>
                                <%
                                    List<ShoppingCartItem> itemsOnCart = scart.getShoppingCartItemList();

                                    for (int i = 0; i < itemsOnCart.size(); i++) {
                                        ShoppingCartItem item = itemsOnCart.get(i);
                                %>
                                <tr>
                                    <td class="cQty"><input type="text" name="newQuantity[<%out.print(i);%>]" value="<% out.print(item.getQuantity());%>" size="2" readonly="true"/></td>
                                    <td class="cRem"><input type="checkbox" name="isRemove[<%out.print(i);%>]" readonly="true" disabled="true"/></td>
                                    <!--value="<% out.print(item.getProduct().getIdProduct());%>"-->
                                    <td class="cDes">
                                        <div class="productTinyImage">
                                            <img src="<% out.print(item.getProduct().getImageurl());%>" alt="img" width="64" height="auto">
                                        </div>
                                        <div class="productInfoCart">
                                            <a href="<%= request.getContextPath()%>/product/<%out.print(item.getProduct().getIdProduct());%>/<% out.print(item.getProduct().getName().replaceAll(" ", "-"));%>" title="<% out.print(item.getProduct().getName());%>">
                                                <% out.print(item.getProduct().getName());%>
                                            </a>
                                        </div>
                                    </td>
                                    <td class="cPri">$<% out.print(item.getPrice());%></td>
                                    <td class="cTot">$<% out.print(item.getPrice() * item.getQuantity());%></td>
                                </tr>
                                <%                                            }
                                %>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td class="cQty">
                                        <s:submit name="button" value="Update" cssStyle="display: inline; width: 76px" theme="simple" disabled="true"/>
                                    </td>
                                    <td class="cRem">
                                        <s:submit name="button" value="Remove" cssStyle="display: inline; width: 76px" theme="simple" disabled="true"/>
                                    </td>
                                    <td class="cDes"><s:actionerror theme="simple" /></td>
                                    <td class="cPri"><b>Subtotal:</b></td>
                                    <td class="cTot">$<% out.print(scart.getTotalAmount());%></td>
                                </tr>
                            </tfoot>
                        </s:form>
                    </table>
                </div>

                <div class="buttonOnShoppingCart">
                    <div class="buttonContinue">
                        <a href="<%= request.getContextPath()%>">Continue Shopping</a>
                    </div>

                    <div class="paypal">
                        <s:form action="doExpressCheckout" namespace="/" method="post">
                            <s:set var="contextPath"><%= request.getContextPath()%></s:set>
                            <s:submit type="image" src="%{contextPath}/css/pay-now.png" theme="simple" title="Pay Now with PayPal"  alt="Pay Now!" cssStyle="vertical-align: middle;"/>
                        </s:form>
                    </div>
                </div>
                    
                <%                        }
                %>
            </div>
        </div>
    </div>
    <div class="footerbg">
        <%@include file="include/iFooter.jsp" %>
    </div>
</body>
</html>

